package com.example.controller;

import com.example.pojo.User;
import com.example.service.UserService;
import com.mongodb.client.result.DeleteResult;
import com.mongodb.client.result.UpdateResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.Mapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program: springboot_course
 * @description: 用户控制层
 * @author: ChenZhiXiang
 * @create: 2019-06-10 16:43
 **/
@RestController
public class UserController {

    @Autowired
    private MongoTemplate template;

    @Autowired
    private UserService userService;

    @PostMapping("/save")
    public Object save(){
        return userService.saveUser();
    }

    @GetMapping("/findAll")
    public Object findAll(){
        return template.find(null,User.class);
    }

    @GetMapping("/getById")
    public User getById(Long id){
        return userService.getUser(id);
    }

    @GetMapping("/deleteUser")
    public DeleteResult deleteUser(Long id){
        return userService.deleteUser(id);
    }

    @GetMapping("/updateUser")
    public UpdateResult updateUser(Long id, String userName, String note){
        return userService.updateUser(id,userName,note);
    }

}
